package api

import (
	"gitee.com/zatto/project/tree/master/vblog/api/apps"
	"gitee.com/zatto/project/tree/master/vblog/api/apps/blog"
	"gitee.com/zatto/project/tree/master/vblog/api/protocol/middleware"
	"github.com/gin-gonic/gin"
)

type handler struct {
	svc blog.Service
}

func (h *handler) Name() string {
	return blog.AppName
}

func (h *handler) Init() error {
	h.svc = apps.GetInternalApp(blog.AppName).(blog.Service)
	return nil
}

// 模块api前缀: /vblog/api/v1/blogs
func (h *handler) RegistryHandler(r gin.IRouter) {
	// 无需验证的接口
	r.GET("/", h.QueryBlog)
	r.GET("/:id", h.DescribeBlog)

	// 需要验证的接口
	r.Use(middleware.AuthFunc)
	r.POST("/", h.CreateBlog)
	r.PUT("/:id", h.PutBlog)
	r.PATCH("/:id", h.PatchBlog)
	r.DELETE("/:id", h.DeleteBlog)
}

func init() {
	apps.RegistryHttp(&handler{})
}
